package com.qxl.forest.business.example;

import com.qxl.forest.core.config.properties.JwtProperties;
import com.qxl.forest.core.util.JwtTokenUtil;
import com.qxl.forest.util.CommRes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: qiuxinlin
 * @Dercription: 测试控制器
 * @Date: 2018/1/5
 */
@RestController
@RequestMapping("/hello")
public class ExampleController {

    @Autowired
    private JwtTokenUtil jwtTokenUtil;
    @Autowired
    private JwtProperties jwtProperties;

    @PostMapping("/save")
    public CommRes hello(@RequestBody SimpleObject simpleObject,HttpServletRequest request) {
        System.out.println(simpleObject.getName());
        String requestHeader = request.getHeader(jwtProperties.getHeader());
        String authToken = requestHeader.substring(7);
        System.out.println(jwtTokenUtil.getClaimFromToken(authToken));
        System.out.println(jwtTokenUtil.getMd5KeyFromToken(authToken));
        return CommRes.successRes();
    }
}
